package br.com.rookgraph;

public class Swap{
	
	private Edge cut;
	
	private Edge replace;
	
	public Swap(Edge cut, Edge replace) {
		super();
		this.cut = cut;
		this.replace = replace;
	}

	public Edge getCut() {
		return cut;
	}

	public void setCut(Edge cut) {
		this.cut = cut;
	}

	public Edge getReplace() {
		return replace;
	}

	public void setReplace(Edge replace) {
		this.replace = replace;
	}
	
	public int diffAlfa(){
		return replace.alfa - cut.alfa;
	}
	
	public int diffGama(){
		return replace.gama - cut.gama;
	}
	
	/**
	 * Compara as duas trocas (this e other), e 
	 * retorna a melhor entre as duas.
	 *   
	 * @param other
	 * @return
	 */
	public Swap isMelhorTroca(Swap other) {
		if(other != null){
		
			if(other.diffAlfa() < this.diffAlfa()){
				return other;
			}else
				if(other.diffAlfa() == this.diffAlfa() &&
					other.diffGama() < this.diffGama()){
					
					return other;
				}
			
		}

		return this;
	}
	
	@Override
	public boolean equals(Object other) {
		if(other instanceof Swap){
			Swap otherEdge = (Swap) other;
			return this.cut.equals(otherEdge.cut) && this.replace.equals(otherEdge.replace); 
		}
		return false; 
	}
	
	@Override
	public String toString() {
		return cut +"<------>"+ replace;
	}

	@Override
	public Object clone() throws CloneNotSupportedException {
		return new Swap(this.cut, this.replace);
	}
}
